import { createRouter, createWebHistory } from "vue-router";
// 在路由配置中使用
import { mockMenuData } from "@/mock/menuData";
import { buildMenuTree, generateRoutes } from "@/utils/routeGenerator";

// 生成路由配置
const menuTree = buildMenuTree(mockMenuData);
const dynamicRoutes = generateRoutes(menuTree);

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/404",
      component: () => import("@/views/error/404.vue"),
      meta: { requiresAuth: true },
    },
    {
      path: "/403",
      component: () => import("@/views/error/403.vue"),
      meta: { requiresAuth: true },
    },
    {
      path: "/login",
      component: () => import("@/views/LoginView.vue"),
      meta: { requiresAuth: true },
    },
    {
      path: "/",
      component: () => import("@/layouts/MainLayout.vue"),
      meta: { requiresAuth: true },
      children: [...dynamicRoutes],
    },
  ],
});

export default router;
